package com.cdutetc.websocketTest.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import com.cdutetc.websocketTest.handler.DataWebSocketHandler;

import lombok.RequiredArgsConstructor;

//表示该类是一个配置类
@Configuration
// 开启WebSocket支持
@EnableWebSocket
@RequiredArgsConstructor
public class WebSocketConfig implements WebSocketConfigurer{
    //设置websocket的入口
    private final DataWebSocketHandler dataWebSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(dataWebSocketHandler, "/data-ws")
        .setAllowedOrigins("*");
    }

}